package task2;

public class LongestSubstring {
    public static String remain(String s1, String s2){
        // 区分长短字符串
        String l = s1.length() > s2.length() ? s1 : s2;
        String s = s1.length() < s2.length() ? s1 : s2;
        String result = "";
        // 循环找出短字符串的所有子串，判断是否为公共子串；
        for(int i = 0; i < s.length(); i++){
            for(int j = 0; j < i; j++){
                String substring = s.substring(j, s.length() - i + j);
                if (l.contains(substring)) {
                    if(result.length() < substring.length()){
                        result = substring;
                    }
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(LongestSubstring.remain("asdafghjka", "aaasdfg"));
    }
}
